package com.tpu.osu.rating.web.services;

import java.io.IOException;

import org.apache.tapestry.ioc.OrderedConfiguration;
import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.services.Request;
import org.apache.tapestry.services.RequestFilter;
import org.apache.tapestry.services.RequestGlobals;
import org.apache.tapestry.services.RequestHandler;
import org.apache.tapestry.services.Response;

public class AppModule {
	
	public RequestFilter buildUtf8Filter(@InjectService("RequestGlobals")
	final RequestGlobals requestGlobals) {
		return new RequestFilter() {
			public boolean service(Request request, Response response, RequestHandler handler) throws IOException {
				requestGlobals.getHTTPServletRequest().setCharacterEncoding("UTF-8");
				return handler.service(request, response);
			}
		};
	}
	
    public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration,
            @InjectService("Utf8Filter") final RequestFilter utf8Filter)
    {
        configuration.add("Utf8Filter", utf8Filter); // handle UTF-8
        //configuration.add("Timing", timingFilter);
    }

}
